﻿@{
    ViewBag.Title = "Asp.Net 使用MySql";
}
<h3>Asp.Net 操作MySql</h3>
<div class="col-lg-12">
    <button class="btn btn-sm btn-primary" id="btnAdd">新增</button>
    <button class="btn btn-sm btn-primary" id="btnEdit">修改</button>
    <button class="btn btn-sm btn-primary" id="btnDel">删除</button>
    <button class="btn btn-sm btn-primary" id="btnQuery">查询</button>
</div>
@section Scripts {
    <script>
        $(function () {
            //新增
            $("#btnAdd").click(function () {
                $.post("@Url.Action("UserAdd","Home")", { type: "Add" }, function (res) {
                    if (res.success) {
                        alert("新增成功");
                    }
                    else {
                        alert(res.msg);
                    }
                })
            });
            //编辑
            $("#btnEdit").click(function () {
                $.post("@Url.Action("UserEdit", "Home")", { type: "Edit" }, function (res) {
                    if (res.success) {
                        alert("编辑成功");
                    }
                    else {
                        alert(res.msg);
                    }
                })
            });
            //删除
            $("#btnDel").click(function () {
                $.post("@Url.Action("UserDel", "Home")", { type: "Del" }, function (res) {
                    if (res.success) {
                        alert("删除成功");
                    }
                    else {
                        alert(res.msg);
                    }
                })
            });
            //查询
            $("#btnQuery").click(function () {
                $.post("@Url.Action("UserQuery", "Home")", { type: "Query" }, function (res) {
                    if (res.success) {
                        console.log(res.msg);
                        console.log(res.data);
                        alert("查询成功");
                    }
                    else {
                        alert(res.msg);
                    }
                })
            });

        });
    </script>
}

